package com.bootdo.blog.dao;

import com.bootdo.blog.domain.ProcessingDO;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
/**
 * 
 * 
 * @author chglee
 * @email 1992lcg@163.com
 * @date 2021-03-07 10:38:32
 */
@Mapper
public interface ProcessingMapper {

	@Select("select `process_id`, `batch`, `process_time`, `number`, `fermentation`, `storage`, `treatment`, `canned`, `device_identifier`, `capacity`, `agent_identity`, `use_level`, `principal`, `telephone` from tb_processing where process_id = #{id}")
	ProcessingDO get(Integer processId);
	
	@Select("<script>" +
	"select * from tb_processing " + 
			"<where>" + 
		  		  "<if test=\"processId != null and processId != ''\">"+ "and process_id = #{processId} " + "</if>" + 
		  		  "<if test=\"batch != null and batch != ''\">"+ "and batch = #{batch} " + "</if>" + 
		  		  "<if test=\"processTime != null and processTime != ''\">"+ "and process_time = #{processTime} " + "</if>" + 
		  		  "<if test=\"number != null and number != ''\">"+ "and number = #{number} " + "</if>" + 
		  		  "<if test=\"fermentation != null and fermentation != ''\">"+ "and fermentation = #{fermentation} " + "</if>" + 
		  		  "<if test=\"storage != null and storage != ''\">"+ "and storage = #{storage} " + "</if>" + 
		  		  "<if test=\"treatment != null and treatment != ''\">"+ "and treatment = #{treatment} " + "</if>" + 
		  		  "<if test=\"canned != null and canned != ''\">"+ "and canned = #{canned} " + "</if>" + 
		  		  "<if test=\"deviceIdentifier != null and deviceIdentifier != ''\">"+ "and device_identifier = #{deviceIdentifier} " + "</if>" + 
		  		  "<if test=\"capacity != null and capacity != ''\">"+ "and capacity = #{capacity} " + "</if>" + 
		  		  "<if test=\"agentIdentity != null and agentIdentity != ''\">"+ "and agent_identity = #{agentIdentity} " + "</if>" + 
		  		  "<if test=\"useLevel != null and useLevel != ''\">"+ "and use_level = #{useLevel} " + "</if>" + 
		  		  "<if test=\"principal != null and principal != ''\">"+ "and principal = #{principal} " + "</if>" + 
		  		  "<if test=\"telephone != null and telephone != ''\">"+ "and telephone = #{telephone} " + "</if>" + 
		  			"</where>"+ 
			" <choose>" + 
	            "<when test=\"sort != null and sort.trim() != ''\">" + 
	                "order by ${sort} ${order}" + 
	            "</when>" + 
				"<otherwise>" + 
	                "order by process_id desc" + 
				"</otherwise>" + 
	        "</choose>"+
			"<if test=\"offset != null and limit != null\">"+
			"limit #{offset}, #{limit}" + 
			"</if>"+
			"</script>")
	List<ProcessingDO> list(Map<String, Object> map);
	
	@Select("<script>" +
	"select count(*) from tb_processing " + 
			"<where>" + 
		  		  "<if test=\"processId != null and processId != ''\">"+ "and process_id = #{processId} " + "</if>" + 
		  		  "<if test=\"batch != null and batch != ''\">"+ "and batch = #{batch} " + "</if>" + 
		  		  "<if test=\"processTime != null and processTime != ''\">"+ "and process_time = #{processTime} " + "</if>" + 
		  		  "<if test=\"number != null and number != ''\">"+ "and number = #{number} " + "</if>" + 
		  		  "<if test=\"fermentation != null and fermentation != ''\">"+ "and fermentation = #{fermentation} " + "</if>" + 
		  		  "<if test=\"storage != null and storage != ''\">"+ "and storage = #{storage} " + "</if>" + 
		  		  "<if test=\"treatment != null and treatment != ''\">"+ "and treatment = #{treatment} " + "</if>" + 
		  		  "<if test=\"canned != null and canned != ''\">"+ "and canned = #{canned} " + "</if>" + 
		  		  "<if test=\"deviceIdentifier != null and deviceIdentifier != ''\">"+ "and device_identifier = #{deviceIdentifier} " + "</if>" + 
		  		  "<if test=\"capacity != null and capacity != ''\">"+ "and capacity = #{capacity} " + "</if>" + 
		  		  "<if test=\"agentIdentity != null and agentIdentity != ''\">"+ "and agent_identity = #{agentIdentity} " + "</if>" + 
		  		  "<if test=\"useLevel != null and useLevel != ''\">"+ "and use_level = #{useLevel} " + "</if>" + 
		  		  "<if test=\"principal != null and principal != ''\">"+ "and principal = #{principal} " + "</if>" + 
		  		  "<if test=\"telephone != null and telephone != ''\">"+ "and telephone = #{telephone} " + "</if>" + 
		  			"</where>"+ 
			"</script>")
	int count(Map<String, Object> map);
	
	@Insert("insert into tb_processing (`batch`, `process_time`, `number`, `fermentation`, `storage`, `treatment`, `canned`, `device_identifier`, `capacity`, `agent_identity`, `use_level`, `principal`, `telephone`)"
	+ "values (#{batch}, #{processTime}, #{number}, #{fermentation}, #{storage}, #{treatment}, #{canned}, #{deviceIdentifier}, #{capacity}, #{agentIdentity}, #{useLevel}, #{principal}, #{telephone})")
	int save(ProcessingDO processing);
	
	@Update("<script>"+ 
			"update tb_processing " + 
					"<set>" + 
		            "<if test=\"processId != null\">`process_id` = #{processId}, </if>" + 
                    "<if test=\"batch != null\">`batch` = #{batch}, </if>" + 
                    "<if test=\"processTime != null\">`process_time` = #{processTime}, </if>" + 
                    "<if test=\"number != null\">`number` = #{number}, </if>" + 
                    "<if test=\"fermentation != null\">`fermentation` = #{fermentation}, </if>" + 
                    "<if test=\"storage != null\">`storage` = #{storage}, </if>" + 
                    "<if test=\"treatment != null\">`treatment` = #{treatment}, </if>" + 
                    "<if test=\"canned != null\">`canned` = #{canned}, </if>" + 
                    "<if test=\"deviceIdentifier != null\">`device_identifier` = #{deviceIdentifier}, </if>" + 
                    "<if test=\"capacity != null\">`capacity` = #{capacity}, </if>" + 
                    "<if test=\"agentIdentity != null\">`agent_identity` = #{agentIdentity}, </if>" + 
                    "<if test=\"useLevel != null\">`use_level` = #{useLevel}, </if>" + 
                    "<if test=\"principal != null\">`principal` = #{principal}, </if>" + 
                    "<if test=\"telephone != null\">`telephone` = #{telephone}, </if>" + 
          					"</set>" + 
					"where process_id = #{processId}"+
			"</script>")
	int update(ProcessingDO processing);
	
	@Delete("delete from tb_processing where process_id =#{processId}")
	int remove(Integer process_id);
	
	@Delete("<script>"+ 
			"delete from tb_processing where process_id in " + 
					"<foreach item=\"processId\" collection=\"array\" open=\"(\" separator=\",\" close=\")\">" + 
						"#{processId}" + 
					"</foreach>"+
			"</script>")
	int batchRemove(Integer[] processIds);
}
